<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 创建对象发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <button>点击获取段子</button>
    <button>点击获取英雄</button>
    <button>本地server</button>
    <button>本地test</button>

    <script>
        //获取按钮
        let btns = document.querySelectorAll('button');
        
        //创建对象
        let axios1 = axios.create({
            baseURL: 'http://api.xiaohigh.com'
        });//create 创建

        let axios2 = axios.create({
            baseURL : "http://127.0.0.1:8090"
        })

        //获取段子
        btns[0].onclick = async function(){
            let result = await axios1.get('/duanzi')
            console.log(result);
        }

        //获取英雄
        btns[1].onclick = async function(){
            let result = await axios1({
                url: '/lol'
            })
            console.log(result);
        }

        //本地服务
        btns[2].onclick = async function(){
            let result = await axios2.get('/server');
            console.log(result);
        }

        btns[3].onclick = async function(){
            let result = await axios2.get('/test');
            console.log(result);
        }
    </script>
</body>
</html>